# import time
#
#
# def count_up_to(n):
#     i = 1
#     while i <= n:
#         yield i
#         i += 1
#
#
# # 使用生成器
# for num in count_up_to(5):
#     time.sleep(1)
#     print(num)
#
# # 在循环中，如果想一次性输出所有结果，使用return，
# # 如果每执行一次就输出一个结果，则使用yield
import time


# def read_large_file(file_path):
#     with open(file_path, 'r', encoding='utf-8') as f:
#         for line in f:
#             time.sleep(1)
#             yield line.strip()


def read_large_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        for line in f:  # 遍历每一行
            for char in line:  # 遍历行中的每一个字符
                time.sleep(0.1)
                yield char  # 每次返回一个字符


for line in read_large_file('demo1.txt'):
    print(line, end='', flush=True)
